
class Stay {
  constructor (stay) {
    this.stay = stay
    this.days = this.getDays()
    this.totalDays = this.getTotalDays()
    this.weekendDays = this.getWeekendDays()
    this.weekDays = this.getWeekDays()
  }

  getClientType () {
    return this.stay.trim().split(':').shift().toLowerCase()
  }

  getStay () {
    return this.stay.trim().split(':').pop()
  }

  getDays () {
    return this.getStay().split(',')
  }

  getWeekDays () {
    return this.totalDays - this.weekendDays
  }

  getTotalDays () {
    return this.days.length
  }

  getWeekendDays () {
    return this.days.map(day => {
      if (this.isWeekend(day)) { return 1 }
      return 0
    }).reduce((dayPrevious, dayCurrent) => {
      return dayPrevious + dayCurrent
    })
  }

  isWeekend (day) {
    const re = /(sat)|(sun)/
    return re.test(day)
  }
}

module.exports = Stay
